package ${package};

import ${tableClass.fullClassName};
import ${servicePackage}.${tableClass.shortClassName}Service;
import ${qmPo}.${tableClass.shortClassName}Query;
import com.revolver.comm.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
<#assign dateTime = .now>
/**
 * @Author: ${author}
 * @Date: ${dateTime?string["yyyy-MM-dd HH:mm:ss"]}
 * @Description: ${description} mvc api
 */
@Controller
@RequestMapping("/${tableClass.variableName}")
public class ${tableClass.shortClassName}Controller {
    private static Logger logger = LoggerFactory.getLogger(${tableClass.shortClassName}Controller.class);

    @Autowired
    private ${tableClass.shortClassName}Service ${tableClass.variableName}Service;

    /**
     * 列表
     *
     * @param model
     * @param entity
     *
     * @return
     */
    @GetMapping("/list")
    public String list(Model model, ${tableClass.shortClassName}Query entity) {
        //
        entity.setDelFlag(Constant.FLAG_N);

        List<${tableClass.shortClassName}> list = ${tableClass.variableName}Service.select(entity);
        model.addAttribute("list", list);
        //
        return "${tableClass.variableName}/list";
    }
    /**
     * 添加
     *
     * @param model
     *
     * @return
     */
    @GetMapping()
    public String toAdd(Model model) {
        //
        return "${tableClass.variableName}/add";
    }

    /**
     * 添加
     *
     * @param entity
     *
     * @return
     */
    @PostMapping()
    public String Add(${tableClass.shortClassName} entity) {
        //
        ${tableClass.variableName}Service.insert(entity);

        return "redirect:/${tableClass.variableName}/list";
    }

    /**
     * 更新
     *
     * @param model
     * @param id
     *
     * @return
     */
    @GetMapping("/update/{id}")
    public String toUpdate(Model model, @PathVariable("id") Integer id) {
        //
        ${tableClass.shortClassName} vo = ${tableClass.variableName}Service.selectByPrimaryKey(id);
        model.addAttribute("vo", vo);
        //
        return "${tableClass.variableName}/add";
    }

    /**
     * 更新
     *
     * @param entity
     *
     * @return
     */
    @PutMapping()
    public String update(${tableClass.shortClassName} entity) {
        //
        ${tableClass.variableName}Service.updateByPrimaryKeySelective(entity);
        return "redirect:/${tableClass.variableName}/list";
    }

    /**
     * 删除
     *
     * @param id
     *
     * @return
     */
    @DeleteMapping("/del/{id}")
    public String delete(@PathVariable("id") Integer id) {
        //
        ${tableClass.shortClassName} entity = new ${tableClass.shortClassName}();
        entity.setId(id);
        entity.setDelFlag(Constant.FLAG_Y);
        ${tableClass.variableName}Service.updateByPrimaryKeySelective(entity);
        return "redirect:/${tableClass.variableName}/list";
    }
}